package com.youi.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.GoodtypeDao;
import com.youi.entity.Goods;
import com.youi.entity.Goodtype;
import com.youi.service.GoodsService;
import com.youi.service.GoodtypeService;

@Service
public class GoodtypeServiceImpl extends BaseServiceImpl<Goodtype> implements GoodtypeService{
		
		private GoodtypeDao goodtypeDao;
		
		@Autowired
		private GoodsService goodsService;
		@Autowired
		public void setfaultRecordDao(GoodtypeDao goodtypeDao){
			this.goodtypeDao=goodtypeDao;
			super.setBaseDAO(goodtypeDao);
		}

		@Override
		public String getGoodsTypeByGoodsId(Long goodsId,Integer type) {
			// TODO Auto-generated method stub
			Map<String, Object> params=new HashMap<String, Object>();
			params.put(Common.DELSTATUS, DelStatus.NODEL);
			params.put(Common.ID, goodsId);
			Goods goods=goodsService.getByParam(params);
			if (goods!=null) {
				params=new HashMap<String, Object>();
				params.put(Common.DELSTATUS, DelStatus.NODEL);
				params.put(Common.ID, goods.getGoodsTypeId());
				Goodtype goodtype=goodtypeDao.getObject(params);
				if (goodtype!=null) {
					if (type==1) {
						return goodtype.getName();
					}else {
						return goodtype.getCode();
					}					
				}
			}
			return null;
		}
}